package com.example.arithmeticleetcode.leetcode.august;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-11 13:39
 **/
public class Demo07 {

    public static void main(String[] args) {
        int[] arr = {2, 3, 4, 7, 11};
        int k = 5;
        System.out.println(findKthPositive(arr, k));

        int[] arr1 = {1, 2, 3, 4};
        int k1 = 2;
        System.out.println(findKthPositive(arr1, k1));
    }

    public static int findKthPositive(int[] arr, int k) {
        List<Integer> arrList = new ArrayList<>();
        for (int i : arr) {
            arrList.add(i);
        }
        int count = 0;
        for (int i = 1, len = arr.length + k; i <= len; i++) {
            if (arrList.contains(i)) {
                continue;
            }
            if (++count == k) {
                return i;
            }
        }
        return -1;
    }
}
